import { createSlice } from '@reduxjs/toolkit';
import { getCurUserDetailAPI } from '@src/apis/login';
import { createParentKey, getParentKey } from '@src/utils';
let bb: any = [
  {
    children: [null],
    hidden: 0,
    parentId: 0,
    remark: 'string',
    resourcesId: 0,
    resourcesMark: 'string',
    resourcesName: 'string',
    resourcesTags: 'string',
    resourcesType: 'string',
  },
  {
    id: 196,
    parentId: 0,
    resourcesTags: '1',
    resourcesName: '个人中心',
    resourcesMark: '/home',
    resourcesWay: null,
    resourcesType: '菜单',
    remark: 'icon-icon7',
    verifyTags: null,
    status: 0,
    hidden: 0,
    orderBy: '0',
    creator: null,
    updater: null,
    createTime: '2021-12-31 18:16:25',
    updateTime: '2021-12-31 18:16:25',
  },
  {
    id: 197,
    parentId: 0,
    resourcesTags: '1',
    resourcesName: '查询管理',
    resourcesMark: '菜单',
    resourcesWay: null,
    resourcesType: '菜单',
    remark: 'icon-chaxun',
    verifyTags: null,
    status: 0,
    hidden: 0,
    orderBy: '1',
    creator: null,
    updater: null,
    createTime: '2021-12-31 18:19:27',
    updateTime: '2021-12-31 18:30:48',
    child: [
      {
        id: 198,
        parentId: 197,
        resourcesTags: '1',
        resourcesName: '订单查询', //左侧导航的名称
        resourcesMark: '/smallPolicy', //左侧导航的路径
        resourcesWay: null,
        resourcesType: '菜单', //左侧导航的类型：菜单、页面、按钮 ：如果是'页面'就代表此导航不在左侧导航展示
        remark: null, //左侧导航的图标
        verifyTags: null,
        status: 0,
        hidden: 0,
        orderBy: '0',
        creator: null,
        updater: null,
        createTime: '2021-12-31 18:19:30',
        updateTime: '2021-12-31 18:19:30',
        child: [
          {
            id: 199,
            parentId: 198,
            resourcesTags: '1',
            resourcesName: '订单详情',
            resourcesMark: '/smallPolicy/detail',
            resourcesWay: null,
            resourcesType: '页面',
            remark: null,
            verifyTags: null,
            status: 0,
            hidden: 0,
            orderBy: '0',
            creator: null,
            updater: null,
            createTime: '2021-12-31 18:19:31',
            updateTime: '2021-12-31 18:19:31',
          },
        ],
      },
      {
        id: 200,
        parentId: 197,
        resourcesTags: '1',
        resourcesName: '批改查询',
        resourcesMark: '/correcting',
        resourcesWay: null,
        resourcesType: '菜单',
        remark: null,
        verifyTags: null,
        status: 0,
        hidden: 0,
        orderBy: '1',
        creator: null,
        updater: null,
        createTime: '2021-12-31 18:19:31',
        updateTime: '2021-12-31 18:19:31',
        child: [
          {
            id: 201,
            parentId: 200,
            resourcesTags: '1',
            resourcesName: '批改查询详情',
            resourcesMark: '/correcting/detail',
            resourcesWay: null,
            resourcesType: '页面',
            remark: null,
            verifyTags: null,
            status: 0,
            hidden: 0,
            orderBy: '0',
            creator: null,
            updater: null,
            createTime: '2021-12-31 18:19:31',
            updateTime: '2021-12-31 18:19:31',
          },
        ],
      },
      {
        id: 202,
        parentId: 197,
        resourcesTags: '1',
        resourcesName: '实时交易数据查询',
        resourcesMark: '/realTimeTransactionData',
        resourcesWay: null,
        resourcesType: '菜单',
        remark: null,
        verifyTags: null,
        status: 0,
        hidden: 0,
        orderBy: '2',
        creator: null,
        updater: null,
        createTime: '2021-12-31 18:28:52',
        updateTime: '2021-12-31 18:28:52',
      },
    ],
  },
  {
    id: 205,
    parentId: 0,
    resourcesTags: '1',
    resourcesName: '配置管理',
    resourcesMark: '配置管理3',
    resourcesWay: null,
    resourcesType: '菜单',
    remark: 'icon-peizhiguanli',
    verifyTags: null,
    status: 0,
    hidden: 0,
    orderBy: '3',
    creator: null,
    updater: null,
    createTime: '2021-12-31 18:35:02',
    updateTime: '2021-12-31 18:35:02',
    child: [
      {
        id: 206,
        parentId: 205,
        resourcesTags: '1',
        resourcesName: '计划配置',
        resourcesMark: '/planConfiguration',
        resourcesWay: null,
        resourcesType: '菜单',
        remark: null,
        verifyTags: null,
        status: 0,
        hidden: 0,
        orderBy: '0',
        creator: null,
        updater: null,
        createTime: '2021-12-31 18:35:02',
        updateTime: '2021-12-31 18:35:02',
        child: [
          {
            id: 207,
            parentId: 206,
            resourcesTags: '1',
            resourcesName: '计划配置批量新增、详情页面',
            resourcesMark: '/batchAddPlan',
            resourcesWay: null,
            resourcesType: '页面',
            remark: null,
            verifyTags: null,
            status: 0,
            hidden: 0,
            orderBy: '0',
            creator: null,
            updater: null,
            createTime: '2021-12-31 18:35:02',
            updateTime: '2021-12-31 18:35:02',
          },
        ],
      },
      {
        id: 208,
        parentId: 205,
        resourcesTags: '1',
        resourcesName: '产品配置',
        resourcesMark: '/productConfiguration',
        resourcesWay: null,
        resourcesType: '菜单',
        remark: null,
        verifyTags: null,
        status: 0,
        hidden: 0,
        orderBy: '1',
        creator: null,
        updater: null,
        createTime: '2021-12-31 18:35:02',
        updateTime: '2021-12-31 18:35:02',
        child: [
          {
            id: 209,
            parentId: 208,
            resourcesTags: '1',
            resourcesName: '产品配置新增、详情页面',
            resourcesMark: '/productConfigurationAdd',
            resourcesWay: null,
            resourcesType: '页面',
            remark: null,
            verifyTags: null,
            status: 0,
            hidden: 0,
            orderBy: '0',
            creator: null,
            updater: null,
            createTime: '2021-12-31 18:35:02',
            updateTime: '2021-12-31 18:35:02',
          },
        ],
      },
    ],
  },
  {
    id: 210,
    parentId: 0,
    resourcesTags: '1',
    resourcesName: '基础管理',
    resourcesMark: '基础管理4',
    resourcesWay: null,
    resourcesType: '菜单',
    remark: 'icon-xitongjichuguanli',
    verifyTags: null,
    status: 0,
    hidden: 0,
    orderBy: '4',
    creator: null,
    updater: null,
    createTime: '2021-12-31 18:35:02',
    updateTime: '2021-12-31 18:35:02',
    child: [
      {
        id: 211,
        parentId: 210,
        resourcesTags: '1',
        resourcesName: '补传管理',
        resourcesMark: '/compensateManage',
        resourcesWay: null,
        resourcesType: '菜单',
        remark: null,
        verifyTags: null,
        status: 0,
        hidden: 0,
        orderBy: '0',
        creator: null,
        updater: null,
        createTime: '2021-12-31 18:35:02',
        updateTime: '2021-12-31 18:35:02',
      },
    ],
  },
  {
    id: 212,
    parentId: 0,
    resourcesTags: '1',
    resourcesName: '系统管理',
    resourcesMark: '系统管理',
    resourcesWay: null,
    resourcesType: '菜单',
    remark: 'icon-xitongjichuguanli',
    verifyTags: null,
    status: 0,
    hidden: 0,
    orderBy: '5',
    creator: null,
    updater: null,
    createTime: '2021-12-31 18:35:02',
    updateTime: '2021-12-31 18:35:02',
    child: [
      {
        id: 213,
        parentId: 212,
        resourcesTags: '1',
        resourcesName: '系统字典',
        resourcesMark: '/systemDictionary',
        resourcesWay: null,
        resourcesType: '菜单',
        remark: null,
        verifyTags: null,
        status: 0,
        hidden: 0,
        orderBy: '0',
        creator: null,
        updater: null,
        createTime: '2021-12-31 18:35:02',
        updateTime: '2021-12-31 18:35:02',
      },
      {
        id: 214,
        parentId: 212,
        resourcesTags: '1',
        resourcesName: '运行环境配置',
        resourcesMark: '/processConfig',
        resourcesWay: null,
        resourcesType: '菜单',
        remark: null,
        verifyTags: null,
        status: 0,
        hidden: 0,
        orderBy: '0',
        creator: null,
        updater: null,
        createTime: '2021-12-31 18:35:02',
        updateTime: '2021-12-31 18:35:02',
      },
    ],
  },
];
let a: any = [
  {
    title: '个人中心',
    key: 'home',
    path: '/home',
    icon: 'icon-icon7',
  },
  {
    title: '查询管理',
    key: 'queryManagement',
    icon: 'icon-chaxun',
    children: [
      {
        title: '订单查询',
        key: 'smallPolicy',
        path: '/smallPolicy',
      },
      {
        title: '订单详情',
        key: 'smallPolicy',
        path: '/smallPolicy/detail',
        meta: {
          routerHidden: true, //是否在左侧菜单隐藏
        },
      },
      {
        title: '批改查询',
        key: 'correcting',
        path: '/correcting',
      },
      {
        title: '批改查询详情',
        key: 'correcting',
        path: '/correcting/detail',
        meta: {
          routerHidden: true,
        },
      },
      {
        title: '实时交易数据查询',
        key: 'realTimeTransactionData',
        path: '/realTimeTransactionData',
      },
    ],
  },
  {
    title: '配置管理',
    key: 'configManagement',
    icon: 'icon-peizhiguanli',
    children: [
      {
        title: '计划配置',
        key: 'planConfiguration',
        path: '/planConfiguration',
      },
      {
        title: '计划配置批量新增、详情页面',
        key: 'planConfiguration',
        path: '/batchAddPlan',
        meta: {
          routerHidden: true, //是否在左侧菜单隐藏
        },
      },
      {
        title: '计划配置、产品配置、详情',
        key: 'planConfiguration',
        path: '/planDetail',
        meta: {
          routerHidden: true, //是否在左侧菜单隐藏
        },
      },
      {
        title: '产品配置',
        key: 'productConfiguration',
        path: '/productConfiguration',
      },
      {
        title: '产品配置新增、详情页面',
        key: 'productConfiguration',
        path: '/productConfigurationAdd',
        meta: {
          routerHidden: true, //是否在左侧菜单隐藏
        },
      },
    ],
  },
  {
    title: '基础管理',
    key: 'basicManagement',
    icon: 'icon-xitongjichuguanli',
    children: [
      {
        title: '补传管理',
        key: 'compensateManage',
        path: '/compensateManage',
      },
    ],
  },
  {
    title: '系统管理',
    key: 'systemManagement',
    icon: 'icon-xitongjichuguanli',
    children: [
      {
        title: '系统字典',
        key: 'systemDictionary',
        path: '/systemDictionary',
      },
      {
        title: '运行环境配置',
        key: 'processConfig',
        path: '/processConfig',
      },
    ],
  },
  {
    title: '测试页面一啊啊名称还很长',
    key: 'basicConfigs',
    icon: 'icon-icon7',
    children: [
      {
        title: 'antdForm',
        key: 'ServiceCategory',
        path: '/ServiceCategory',
      },
    ],
  },
  {
    title: 'js工具类',
    key: 'jstools',
    icon: 'icon-icon7',
    children: [
      {
        title: 'md5',
        key: 'Md5',
        path: '/Md5',
      },
      {
        title: 'PublicPage',
        key: 'PublicPage',
        path: '/PublicPage',
      },
      {
        title: 'reduxToolkit',
        key: 'reduxToolkit',
        path: '/reduxToolkit',
      },
      {
        title: '遥想公瑾当年',
        key: 'Maintain',
        path: '/Maintain/detail',

        meta: {
          routerHidden: false,
        },
      },
      {
        title: '小乔初嫁了',
        key: 'Deal',
        path: '/Deal',
      },
      {
        title: '没得办法啊',
        key: 'Deal',
        path: '/Deal/detail',

        meta: {
          routerHidden: true,
        },
      },
    ],
  },
  {
    title: '测试页面三',
    key: 'service',
    icon: 'icon-icon7',
    children: [
      {
        title: 'js工具类2',
        key: 'jstools2',
        icon: 'icon-icon7',
        children: [
          {
            title: 'md52',
            key: 'Md52',
            path: '/Md52',
          },
          {
            title: 'reduxToolkit2',
            key: 'reduxToolkit2',
            path: '/reduxToolkit2',
          },
          {
            title: '遥想公瑾当年2',
            key: 'Maintain2',
            path: '/Maintain/detail2',

            meta: {
              routerHidden: false,
            },
          },
          {
            title: '小乔初嫁了2',
            key: 'Deal2',
            path: '/Deal2',
          },
          {
            title: '没得办法啊2',
            key: 'Deal2',
            path: '/Deal/detail2',

            meta: {
              routerHidden: true,
            },
          },
        ],
      },
      {
        title: '我欲乘风归去',
        key: 'ServiceConfig',
        path: '/ServiceConfig',
      },
      {
        title: '又恐琼楼玉宇',
        key: 'ServiceConfig',
        path: '/ServiceConfig/Detail',

        meta: {
          routerHidden: true,
        },
      },
      {
        title: '高处不胜寒',
        key: 'ServiceConfig',
        path: '/ServiceConfig/Add',

        meta: {
          routerHidden: true,
        },
      },
      {
        title: '天天向上',
        key: 'ServiceProject',
        path: '/ServiceProject',
      },
    ],
  },
  {
    title: '快乐大本营',
    key: 'settle',
    icon: 'icon-icon7',
    children: [
      {
        title: '谢娜主页',
        key: 'Bill',
        path: '/Bill',
      },
      {
        title: '何炅主页',
        key: 'Bill',
        path: '/BillAdd',

        meta: {
          routerHidden: true,
        },
      },
      {
        title: '李维嘉主页',
        key: 'Bill',
        path: '/Bill/StatementGenerate',

        meta: {
          routerHidden: true,
        },
      },
      {
        title: '杜海涛主页',
        key: 'Bill',
        path: '/statement/detail',

        meta: {
          routerHidden: true,
        },
      },
      {
        title: '吴昕主页',
        key: 'Statement',
        path: '/Statement',
      },
    ],
  },
];
let b: any = [
  {
    resourcesId: 196,
    parentId: -1,
    resourcesName: '个人中心',
    resourcesMark: '/home',
    resourcesType: '菜单',
    remark: 'icon-icon7',
    hidden: 1,
    resourcesTags: '1',
    children: null,
  },
  {
    resourcesId: 197,
    parentId: -1,
    resourcesName: '查询管理',
    resourcesMark: '菜单',
    resourcesType: '菜单',
    remark: 'icon-chaxun',
    hidden: 1,
    resourcesTags: '1',
    children: [
      {
        resourcesId: 198,
        parentId: 197,
        resourcesName: '订单查询',
        resourcesMark: '/smallPolicy',
        resourcesType: '菜单',
        remark: null,
        hidden: 1,
        resourcesTags: '1',
        children: [
          {
            resourcesId: 199,
            parentId: 198,
            resourcesName: '订单详情',
            resourcesMark: '/smallPolicy/detail',
            resourcesType: '页面',
            remark: null,
            hidden: 1,
            resourcesTags: '1',
            children: null,
          },
        ],
      },
      {
        resourcesId: 200,
        parentId: 197,
        resourcesName: '批改查询',
        resourcesMark: '/correcting',
        resourcesType: '菜单',
        remark: null,
        hidden: 1,
        resourcesTags: '1',
        children: [
          {
            resourcesId: 201,
            parentId: 200,
            resourcesName: '批改查询详情',
            resourcesMark: '/correcting/detail',
            resourcesType: '页面',
            remark: null,
            hidden: 1,
            resourcesTags: '1',
            children: null,
          },
        ],
      },
      {
        resourcesId: 202,
        parentId: 197,
        resourcesName: '实时交易数据查询',
        resourcesMark: '/realTimeTransactionData',
        resourcesType: '菜单',
        remark: null,
        hidden: 1,
        resourcesTags: '1',
        children: null,
      },
    ],
  },
  {
    resourcesId: 205,
    parentId: -1,
    resourcesName: '配置管理',
    resourcesMark: '配置管理3',
    resourcesType: '菜单',
    remark: 'icon-peizhiguanli',
    hidden: 1,
    resourcesTags: '1',
    children: [
      {
        resourcesId: 206,
        parentId: 205,
        resourcesName: '计划配置',
        resourcesMark: '/planConfiguration',
        resourcesType: '菜单',
        remark: null,
        hidden: 1,
        resourcesTags: '1',
        children: [
          {
            resourcesId: 207,
            parentId: 206,
            resourcesName: '计划配置批量新增、详情页面',
            resourcesMark: '/batchAddPlan',
            resourcesType: '页面',
            remark: null,
            hidden: 1,
            resourcesTags: '1',
            children: null,
          },
        ],
      },
      {
        resourcesId: 208,
        parentId: 205,
        resourcesName: '产品配置',
        resourcesMark: '/productConfiguration',
        resourcesType: '菜单',
        remark: null,
        hidden: 1,
        resourcesTags: '1',
        children: [
          {
            resourcesId: 209,
            parentId: 208,
            resourcesName: '产品配置新增、详情页面',
            resourcesMark: '/productConfigurationAdd',
            resourcesType: '页面',
            remark: null,
            hidden: 1,
            resourcesTags: '1',
            children: null,
          },
        ],
      },
    ],
  },
  {
    resourcesId: 212,
    parentId: -1,
    resourcesName: '系统管理',
    resourcesMark: '系统管理',
    resourcesType: '菜单',
    remark: 'icon-peizhiguanli',
    hidden: 1,
    resourcesTags: '1',
    children: [
      {
        resourcesId: 213,
        parentId: 212,
        resourcesName: '系统字典',
        resourcesMark: '/systemDictionary',
        resourcesType: '菜单',
        remark: null,
        hidden: 1,
        resourcesTags: '1',
        children: null,
      },
      {
        resourcesId: 214,
        parentId: 212,
        resourcesName: '运行环境配置',
        resourcesMark: '/processConfig',
        resourcesType: '菜单',
        remark: null,
        hidden: 1,
        resourcesTags: '1',
        children: null,
      },
      {
        resourcesId: 215,
        parentId: 212,
        resourcesName: '流程节点配置',
        resourcesMark: '/processNodeConfig',
        resourcesType: '菜单',
        remark: null,
        hidden: 1,
        resourcesTags: '1',
        children: null,
      },
      {
        resourcesId: 216,
        parentId: 212,
        resourcesName: '角色管理',
        resourcesMark: '/roleManagement',
        resourcesType: '菜单',
        remark: null,
        hidden: 1,
        resourcesTags: '1',
        children: null,
      },
      {
        resourcesId: 217,
        parentId: 212,
        resourcesName: '用户管理',
        resourcesMark: '/userManagement',
        resourcesType: '菜单',
        remark: null,
        hidden: 1,
        resourcesTags: '1',
        children: null,
      },
    ],
  },
];
// createParentKey(a, '');
createParentKey(b, '', 'resourcesId');
// console.log(b);
export const slice = createSlice({
  name: 'base',
  initialState: {
    routeArray: b, //[], //b,
    roleObj: {
      roleName: '未登录',
    },
  },
  reducers: {
    changeRouteArray: (state, { payload }) => {
      createParentKey(payload, '', 'resourcesId');
      // state.routeArray = payload;
      // //单纯测试使用
      // let win: any = window;
      // win.aaa = payload;
    },
    changeRoleObj: (state, { payload }) => {
      state.roleObj = payload;
      //单纯测试使用
      let win: any = window;
      win.aaa = payload;
    },
  },
});
export const getCurUserDetailAPIF = (amount?: any) => (dispatch: any) => {
  getCurUserDetailAPI({}).then((result: any) => {
    console.log(result.data);
    dispatch(changeRouteArray(result.data.resourcesListTreeList));
    dispatch(changeRoleObj(result.data));
  });
};

export const { changeRouteArray, changeRoleObj } = slice.actions;
export const routeArrayR = (state: any) => state.baseReducer.routeArray;
export const roleObjR = (state: any) => state.baseReducer.roleObj;
export default slice.reducer;
